package org.linuxgears.BouncingBall.mover.strategy;

import org.linuxgears.BouncingBall.model.Point;

// pattern: Decorator
public class PausableMovingStrategy implements ProgressiveMovingStrategy {

	private enum State { PAUSED, RUNNING };
	private State state;
	private ProgressiveMovingStrategy strategy;
	
	public PausableMovingStrategy(ProgressiveMovingStrategy strategy) {
		state = State.RUNNING;
		this.strategy = strategy;
	}

	@Override
	public Point getPosition() {
		return strategy.getPosition();
	}

	@Override
	public void move() {
		if (state == State.RUNNING) {
			strategy.move();
		}
	}

	@Override
	public void setPosition(Point position) {
		strategy.setPosition(position);
	}

	@Override
	public void setTargetPoint(Point target) {
		strategy.setTargetPoint(target);
	}

	public void pause() {
		state = State.PAUSED;
	}
	
	public void resume() {
		state = State.RUNNING;
	}
	
	public void toggle() {
		if (state == State.PAUSED) {
			resume();
		} else {
			pause();
		}
	}

	@Override
	public Point getVelocity() {
		return strategy.getVelocity();
	}

	@Override
	public void setVelocity(Point velocity) {
		strategy.setVelocity(velocity);
	}
}
